package io.lkt.modules.sys.controller;
import io.lkt.common.util.Query;
import io.lkt.common.utils.DateUtil;
import io.lkt.common.utils.PageUtils;
import io.lkt.common.utils.R;
import io.lkt.modules.sys.entity.BSlideshowInfoEntity;
import io.lkt.modules.sys.service.BSlideshowInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("sys/bslideshowinfo")
public class BSlideshowInfoController {
    @Autowired
    private BSlideshowInfoService bSlideshowInfoService;

    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        Query query = new Query(params);
        List<BSlideshowInfoEntity> list = bSlideshowInfoService.getList(query);
        int total = bSlideshowInfoService.getListTotal(query);

        PageUtils page = new PageUtils(list, total, query.getLimit(), query.getPage());
        return R.ok().put("page", page);
    }

    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id) {
        BSlideshowInfoEntity slideshowInfo = bSlideshowInfoService.getById(id);
        return R.ok().put("slideshowInfo", slideshowInfo);
    }

    @RequestMapping("/save")
    public R save(@RequestBody BSlideshowInfoEntity entity) {
        entity.setCreateTime(DateUtil.getCurDate());
        bSlideshowInfoService.save(entity);
        return R.ok();
    }

    @RequestMapping("/update")
    public R update(@RequestBody BSlideshowInfoEntity entity) {
        entity.setModifyTime(DateUtil.getCurDate());
        bSlideshowInfoService.updateById(entity);
        return R.ok();
    }
}
